import sys,getopt,logging,os


def main(argv):
    import grepxp
    o = grepxp.Opt()
    try:
        opts,args = getopt.getopt(argv,"hd:c:f:s:")
    except getopt.GetoptError:
        print("grepex.py -d <dir> -c <content>")
        sys.exit(2)

    for opt ,arg in opts:
        match opt:
            case '-h':
                print("grepex.py -d <dir> -c <content>")
            case '-d':
                o.dir=arg
            case '-c':
               o.content=arg
            case "-f":
                o.field.fromString(arg)
            case "-s":
                o.sheetName = arg

    if o.sheetName =="" and o.content == "":
        logging.error("content is empty")
        sys.exit(2)

    if o.dir == "":
        o.dir = os.getcwd()

    grepxp.printret(grepxp.find(o))

if __name__ == '__main__':
    logging.basicConfig(level=logging.INFO)
    cwd = os.getcwd()
    sys.path.append(cwd)
    sys.path.append(os.path.join(cwd,'grepxp'))
    # print(sys.path)
    main(sys.argv[1:])